﻿using _9jCardRegisterCollection.Utils;
using CardRegisterCollection.Model;
using System;
using System.Windows.Forms;
using AntdUI;

namespace _9jCardRegisterCollection.Views
{
    public partial class RoleAdd : UserControl
    {
        public RoleAdd(Window _window, Role _role)
        {
            this._role = _role;
            window = _window;
            InitializeComponent();
            //设置默认值
            InitData();
        }

        private Role _role;
        private Window window;


        public bool Submit { set; get; }


        private void InitData()
        {
            this.txtName.Text = string.Empty;
            if (_role != null)
            {
                this.txtName.Text = _role.name;
            }
            this.txtDescription.Text = string.Empty;
            if (_role != null)
            {
                this.txtDescription.Text = _role.name;
            }
        }

        private void butCreate_Click(object sender, EventArgs e)
        {
            if (!Validation.CheckEmpty(window, this.txtName, "请输入名称"))
            {
                return;
            }
            _role.name = this.txtName.Text;
            _role.description = this.txtDescription.Text;
            Submit = true;
            this.Dispose();
        }

        private void butCancel_Click(object sender, EventArgs e)
        {
            Submit = false;
            this.Dispose();
        }
    }
}
